//用户小程序（我的）
import $http from "@/ajax/http.js";

export const personal_users = {
	data() {
		return {
			userRoles: '2',
			roles: "",
			token: '',
			myaccount: '',
			myphone: '',
			myviptime: '',
			citys: '',
			nickname: ''
		};
	},
	onLoad(options) {
		this.token = wx.getStorageSync('token');
		this.roles = wx.getStorageSync('userRole');
		if (this.roles === this.userRoles) {
			this.init();
			this.inits();
		}
	},
	methods: {
		init() {
			$http.request({
				header: {
					Authorization: this.token,
				},
				url: "/storeuser/my/getLeftVipTime",
				method: "GET",
			}).then((res) => {
				this.myaccount = res.userAccount;

				const endTimeDate = new Date(res.userEndTime);
				const formattedDate = endTimeDate.toISOString().split('T')[0]; // "2024-02-28"  

				this.myviptime = formattedDate;
				console.log(res, "我的门店");
			});

		},

		inits() {
			$http.request({
				header: {
					Authorization: this.token,
				},
				url: "/storeuser/my/getRegAndStore",
				method: "GET",
			}).then((res) => {
				this.citys = res.registerPlace
				this.nickname = res.storeName
				this.myphone = res.storeUserPhone
				console.log(res, "我的门店2");
			});
		},

		record() {
			wx.navigateTo({
				url: '/pages/record/index'
			});
		},

		invoice() {
			wx.navigateTo({
				url: '/pages/invoice/index'
			});
		},

		quit() {
			wx.showModal({
				title: "退出登录",
				content: "请您确定是否退出？",
				success: res => {
					if (res.confirm) {
						wx.redirectTo({
							url: '/pages/login/index'
						});
						wx.removeStorageSync('token');
						wx.removeStorageSync('userRole');
					}
				}
			});
		}
	}
}